package site.teamo.biu.flink.web.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author 爱做梦的锤子
 * @create 2020/11/13
 */

@Configuration
@EnableOpenApi
public class Swagger3Config {

    @Value("${biu-flink.swagger.enable}")
    private boolean swaggerEnable;

    @Value("${biu-flink.swagger.base-package}")
    private String basePackage;

    @Value("${biu-flink.swagger.project.title:Api}")
    private String title;

    @Value("${biu-flink.swagger.project.description:描述信息}")
    private String description;

    @Value("${biu-flink.swagger.project.terms-of-service-url:http://xxx.com}")
    private String termsOfServiceUrl;

    @Value("${biu-flink.swagger.project.version:1.0.0}")
    private String version;

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .enable(swaggerEnable)
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .termsOfServiceUrl(termsOfServiceUrl)
                .version(version)
                .build();
    }
}
